import Vue from 'vue';
import VueRouter from 'vue-router';
import Vuex from 'vuex'
import VueBus from './vue-bus/vue-bus.js'

import App from './app.vue';


Vue.use(VueRouter);
Vue.use(Vuex)
Vue.use(VueBus)
// 路由配置
const Routers = [
	{
	    path: '/about2',
	    meta: {
	        title: 'about2'
	    },
	    component: (resolve) => require(['./views/about2.vue'], resolve)
	},
    {
        path: '/index',
        meta: {
            title: '首页'
        },
        component: (resolve) => require(['./views/index.vue'], resolve)
    },
    {
        path: '/about',
        meta: {
            title: '关于'
        },
        component: (resolve) => require(['./views/about.vue'], resolve)
    },
    {
        path: '/user/:id',
        meta: {
            title: '个人主页'
        },
        component: (resolve) => require(['./views/user.vue'], resolve)
    },
    {
        path: '*',
        redirect: '/index'
    }
];
const RouterConfig = {
    // 使用 HTML5 的 History 路由模式
    mode: 'history',
    routes: Routers
};

const router = new VueRouter(RouterConfig);
const store = new Vuex.Store({
	//vuex的配置 
	state:{
		count:10
	},
	mutations:{
		increment(state,n){
			state.count += n; 
		},
		decrease(state){
			state.count --
		}
	}
})


router.beforeEach((to, from, next) => {
    window.document.title = to.meta.title;
    next();
});

router.afterEach((to, from, next) => {
    window.scrollTo(0, 0);
});

new Vue({
    el: '#app',
    router: router,
	//使用vuex 
	store:store,
    render: h => {
        return h(App)
    }
});